<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Gregwar\Captcha\CaptchaBuilder;
use Session;

class CaptchaController extends Controller
{ 
   public function test(Request $req){
        $builder = new CaptchaBuilder;
        //可以设置图片宽高及字体
        $builder->build($width = 100, $height = 40, $font = null);
        //获取验证码的内容
        $phrase = $builder->getPhrase();

        //把内容存入session
        Session::flash('milkcaptcha', $phrase);
        //生成图片
        header("Cache-Control: no-cache, must-revalidate");
        header('Content-Type: image/jpeg');
        $builder->output();
        die;
   

   }

   public function send($mobile){
    
$curl=curl_init();
$code=mt_rand(11111,99999);
session_start();
$_SESSION['smg'] = $code;
$url="http://120.24.161.220:8800/SMS/Send?account=26C41ED89BCA4D309CD8DFAAE65AD4A2&token=b826b01e6cb44ea8a4c91c18ad8955cc&mobile={$mobile}&content=【短信来了】您的验证码为：{$code}，如非本人操作，请忽略。&type=1";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res=curl_exec($curl);
curl_close($curl);
var_dump($res);
 

   }

   public function check(Request $req,$str){
    session_start();
    //$_SESSION['smg'] = 'hello';

    $value=$_SESSION['smg']; 
    
    //$value=file_get_contents('a.txt');
    if($value==$str){
      echo 1;
    }else{
      echo  0;
    }
    //return $value;
   }

}
